package com.schoolai.entity.jpa;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 菜单信息表
 * </p>
 *
 * @author bobby
 * @since 2025-10-14
 */
@Data
@Entity
@Schema(name = "SysMenu", description = "菜单信息表")
public class SysMenu implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 菜单 ID
     */
    @Schema(description = "菜单 ID")
    @Id
    @GeneratedValue(strategy= GenerationType.UUID)
    private String id;


    /**
     * 菜单名称
     */
    @Schema(description = "菜单名称")
    private String name;

    /**
     * 请求地址
     */
    @Schema(description = "请求地址")
    private String url;

    /**
     * 类型(1目录，2菜单，3按钮)
     */
    @Schema(description = "类型(1目录，2菜单，3按钮)")
    private Integer type;

    /**
     * 授权标识符
     */
    @Schema(description = "授权标识符")
    private String code;

    /**
     * 图标
     */
    @Schema(description = "图标")
    private String icon;

    /**
     * 排序
     */
    @Schema(description = "排序")
    private Integer sort;

    /**
     * 备注
     */
    @Schema(description = "备注")
    private String remark;

    /**
     * 创建时间
     */
    @Schema(description = "创建时间")
    private Date createDate;

    /**
     * 更新时间
     */
    @Schema(description = "更新时间")
    private Date updateDate;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "sys_role_menu",
            joinColumns = @JoinColumn(name = "menu_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id")
    )
    @JsonBackReference
    private List<SysRole> sysRoleList = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    @JsonIgnore
    SysMenu parent;

    @OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST)
    private List<SysMenu> sysMenuList = new ArrayList<>();

}
